package com.topnav.mc.schedule.job;

import com.js.lib.cache.SysCache;
import com.topnav.mc.uitls.TaskLockUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 *
 * @类名: ClearExpireOnCacheJob
 * @说明: 清理缓存过期键
 *
 * @author: kenny
 * @Date	2022年1月26日上午9:51:17
 * 修改记录：
 *
 * @see
 */
@Component
@Slf4j
public class ClearExpireOnCacheJob implements Job, Serializable {
    private static final long serialVersionUID = 5760733013858005036L;
    @Resource
    private SysCache sysCache;
    @Autowired
    private TaskLockUtil taskLockUtil;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String lockKey="LOCK_"+serialVersionUID;
        if (taskLockUtil.isLock(lockKey)) {return;}
        try{
            taskLockUtil.lock(lockKey,5*60);

            sysCache.clearExpireData();

            //强制内存回收
            System.gc();

        }catch(Exception e){
            log.error(">>>>>>>> clearExpireData错误 ： {}",e);
        }finally{
            taskLockUtil.unLock(lockKey);
        }
    }
}
